/*
https://leetcode.cn/problems/sum-of-absolute-differences-in-a-sorted-array/submissions/583163095/
1685. 有序数组中差绝对值之和
*/
class Solution {
public:
    vector<int> getSumAbsoluteDifferences(vector<int>& nums) {
        int sum=0;
        int n=nums.size();
        vector<int>qzh(n,0);qzh[0]=nums[0];
        for(int i=1;i<n;++i)
        {
            qzh[i]=qzh[i-1]+nums[i];
        }
        vector<int>res(n,0);

        for(int i=0;i<n;++i){
            res[i]=nums[i]*(i+1)-qzh[i]+qzh[n-1]-qzh[i]-nums[i]*(n-i-1);
        }
        return res;
    }
};